package com.fr.chart.core.glyph;

import com.fr.base.background.Background;
import com.fr.base.background.IntervalColorBackground;
import com.fr.base.core.IteratorChain;
import com.fr.base.core.json.JSONException;
import com.fr.base.core.json.JSONObject;
import com.fr.base.xml.XMLPrintWriter;
import com.fr.base.xml.XMLableReader;
import com.fr.chart.GeneralInfo;
import com.fr.chart.axis.ValueAxis;
import com.fr.chart.base.equals.Equals;
import com.fr.chart.math.Plot3D;
import com.fr.chart.plot.DataPoint;
import com.fr.chart.plot.DataSeries;
import com.fr.chart.shape3d.Cubic;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.geom.Rectangle2D;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public abstract class CategoryPlotGlyph extends PlotGlyph
{
  private static final long serialVersionUID = 4363652839224475272L;
  public static final String XML_TAG = "CategoryPlotGlyph";
  protected ValueAxisGlyph valueAxisGlyph;
  protected CategoryAxisGlyph categoryAxisGlyph;
  protected boolean isStacked = false;

  public void layoutAxisGlyph()
  {
    Rectangle2D localRectangle2D = getBounds();
    this.categoryAxisGlyph.dealPlotBoundsWithAxisLabel(localRectangle2D);
    this.valueAxisGlyph.dealPlotBoundsWithAxisLabel(localRectangle2D);
    this.categoryAxisGlyph.calculateAxisGlyph(localRectangle2D);
    this.valueAxisGlyph.calculateAxisGlyph(localRectangle2D);
    setBounds(localRectangle2D);
    Background localBackground = getInfo().getBackground();
    if (localBackground instanceof IntervalColorBackground)
    {
      IntervalColorBackground localIntervalColorBackground = (IntervalColorBackground)localBackground;
      localIntervalColorBackground.setIntervalLength(this.valueAxisGlyph.getUnit() * this.valueAxisGlyph.getUnitLen());
    }
  }

  public void layout3DAxisGlyph()
  {
    Plot3D localPlot3D = (Plot3D)this;
    double d1 = getBounds().getWidth();
    double d2 = getBounds().getHeight();
    Cubic localCubic = new Cubic(0.0D, 0.0D, d1, d2);
    int i = localPlot3D.getDeep();
    if (i == -1)
      i = (int)d1;
    if ((this instanceof Bar3DPlotGlyph) && (((Bar3DPlotGlyph)this).isHorizontalDrawBar()))
      i = 100;
    localCubic.setDeep(i);
    localCubic.setProjection(localPlot3D.getProjection());
    localCubic.setInfo(getInfo());
    localCubic.setCovers(new byte[] { 5, 2, 1 });
    if (this.categoryAxisGlyph instanceof CategoryAxis3DGlyph)
      ((CategoryAxis3DGlyph)this.categoryAxisGlyph).setCubic(localCubic);
    else
      ((DateAxis3DGlyph)this.categoryAxisGlyph).setCubic(localCubic);
    ((ValueAxis3DGlyph)this.valueAxisGlyph).setCubic(localCubic);
  }

  public Iterator selectableChildren()
  {
    ArrayList localArrayList = new ArrayList();
    if (this.valueAxisGlyph != null)
      localArrayList.add(this.valueAxisGlyph);
    if (this.categoryAxisGlyph != null)
      localArrayList.add(this.categoryAxisGlyph);
    return new IteratorChain(new Iterator[] { super.selectableChildren(), localArrayList.iterator() });
  }

  public void draw(Graphics paramGraphics)
  {
    Graphics2D localGraphics2D = (Graphics2D)paramGraphics;
    localGraphics2D.translate(getBounds().getX(), getBounds().getY());
    if (this.valueAxisGlyph != null)
      this.valueAxisGlyph.draw(paramGraphics);
    if (this.categoryAxisGlyph != null)
      this.categoryAxisGlyph.draw(paramGraphics);
    localGraphics2D.translate(-getBounds().getX(), -getBounds().getY());
    super.draw(localGraphics2D);
  }

  public double getDataPointPercentValue(int paramInt1, int paramInt2)
  {
    ValueAxis localValueAxis = (ValueAxis)this.valueAxisGlyph.getAxis();
    double d1 = getSeries(paramInt1).getDataPoint(paramInt2).getValue();
    if (!(localValueAxis.isPercentage()))
      return d1;
    double d2 = 0.0D;
    for (int i = 0; i < getSeriesSize(); ++i)
    {
      DataSeries localDataSeries = getSeries(i);
      d2 += Math.abs(localDataSeries.getDataPoint(paramInt2).getValue());
    }
    if (d2 == 0.0D)
      return 0.0D;
    return (d1 / d2);
  }

  public void setValueAxisGlyph(ValueAxisGlyph paramValueAxisGlyph)
  {
    this.valueAxisGlyph = paramValueAxisGlyph;
  }

  public ValueAxisGlyph getValueAxisGlyph()
  {
    return this.valueAxisGlyph;
  }

  public void setCategoryAxisGlyph(CategoryAxisGlyph paramCategoryAxisGlyph)
  {
    this.categoryAxisGlyph = paramCategoryAxisGlyph;
  }

  public CategoryAxisGlyph getCategoryAxisGlyph()
  {
    return this.categoryAxisGlyph;
  }

  public void setStacked(boolean paramBoolean)
  {
    this.isStacked = paramBoolean;
  }

  public boolean isStacked()
  {
    return this.isStacked;
  }

  public boolean equals(Object paramObject)
  {
    if (!(paramObject instanceof CategoryPlotGlyph))
      return false;
    CategoryPlotGlyph localCategoryPlotGlyph = (CategoryPlotGlyph)paramObject;
    if (!(super.equals(localCategoryPlotGlyph)))
      return false;
    if (localCategoryPlotGlyph.isStacked != this.isStacked)
      return false;
    if (!(Equals.equals(localCategoryPlotGlyph.categoryAxisGlyph, this.categoryAxisGlyph)))
      return false;
    return (Equals.equals(localCategoryPlotGlyph.valueAxisGlyph, this.valueAxisGlyph));
  }

  public void writeXML(XMLPrintWriter paramXMLPrintWriter)
  {
    paramXMLPrintWriter.startTAG("CategoryPlotGlyph");
    super.writeXML(paramXMLPrintWriter);
    paramXMLPrintWriter.startTAG("Attr").attr("stacked", this.isStacked).end();
    if (this.valueAxisGlyph != null)
      this.valueAxisGlyph.writeXML(paramXMLPrintWriter);
    if (this.categoryAxisGlyph != null)
      this.categoryAxisGlyph.writeXML(paramXMLPrintWriter);
    paramXMLPrintWriter.end();
  }

  public void readXML(XMLableReader paramXMLableReader)
  {
    super.readXML(paramXMLableReader);
    if (paramXMLableReader.isChildNode())
    {
      String str1 = paramXMLableReader.getTagName();
      if (str1.equals("Attr"))
      {
        String str2;
        if ((str2 = paramXMLableReader.getAttr("stacked")) != null)
          this.isStacked = Boolean.valueOf(str2).booleanValue();
      }
      else if (str1.equals("ValueAxisGlyph"))
      {
        this.valueAxisGlyph = ((ValueAxisGlyph)paramXMLableReader.readXMLObject(new ValueAxisGlyph()));
      }
      else if (str1.equals("CategoryAxisGlyph"))
      {
        this.categoryAxisGlyph = ((CategoryAxisGlyph)paramXMLableReader.readXMLObject(new CategoryAxisGlyph()));
      }
    }
  }

  public Object clone()
    throws CloneNotSupportedException
  {
    CategoryPlotGlyph localCategoryPlotGlyph = (CategoryPlotGlyph)super.clone();
    if (this.valueAxisGlyph != null)
      localCategoryPlotGlyph.valueAxisGlyph = ((ValueAxisGlyph)this.valueAxisGlyph.clone());
    if (this.categoryAxisGlyph != null)
      localCategoryPlotGlyph.categoryAxisGlyph = ((CategoryAxisGlyph)this.categoryAxisGlyph.clone());
    return localCategoryPlotGlyph;
  }

  public JSONObject toJSONObject()
    throws JSONException
  {
    JSONObject localJSONObject = super.toJSONObject();
    localJSONObject.put("isStacked", this.isStacked);
    if (this.categoryAxisGlyph != null)
    {
      localJSONObject.put("categoryGlyphType", this.categoryAxisGlyph.getJSAxisType());
      localJSONObject.put("categoryAxisGlyph", this.categoryAxisGlyph.toJSONObject());
    }
    if (this.valueAxisGlyph != null)
    {
      localJSONObject.put("valueGlyphType", this.valueAxisGlyph.getJSAxisType());
      localJSONObject.put("valueAxisGlyph", this.valueAxisGlyph.toJSONObject());
    }
    return localJSONObject;
  }
}